package com.ad.pet.app.account.order;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.ad.pet.DaggerMainActivityCompent;
import com.ad.pet.R;
import com.ad.pet.app.Navigation;
import com.ad.pet.app.account.adapter.ServiceCollectionAdapter;
import com.ad.pet.app.collect.CollecContract;
import com.ad.pet.app.collect.CollectPresenter;
import com.ad.pet.common.structure.mvp.BasePresenter;
import com.ad.pet.common.structure.ui.activity.AppToolbarActivity;
import com.ad.pet.models.remote.account.order.OrderType;
import com.ad.pet.ui.SimpleDividerDecoration;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * Created by liuyixiang on 2019/11/9.
 */

public class ServleceCollectionActivity extends AppToolbarActivity implements CollecContract.View{

    @BindView(R.id.recycler_service)
    RecyclerView recyclerService;
    private ServiceCollectionAdapter serviceCollectionAdapter;
    @Inject
    CollectPresenter collectPresenter;

    @Override
    protected void init(Bundle savedInstanceState) {
        super.init(savedInstanceState);
        mToolbar.setTitle("服务收藏");

    }

    @Override
    protected int contentLayout() {
        return R.layout.activity_servlece_collection;
    }

    @Override
    protected void clickRetry(View v) {

    }

    @Override
    protected void initViews() {
            collectPresenter.onCreate(this);
            collectPresenter.getCollectGoods("2");
    }

    @Override
    protected void initData() {

        serviceCollectionAdapter = new ServiceCollectionAdapter(null);
        recyclerService.setLayoutManager(new LinearLayoutManager(this));
        recyclerService.setAdapter(serviceCollectionAdapter);
        serviceCollectionAdapter.bindToRecyclerView(recyclerService);
        recyclerService.addItemDecoration(new SimpleDividerDecoration(this,2,R.color.graycf));

    }

    @Override
    protected void initEvents() {
            serviceCollectionAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    Navigation.goServiceDetail(mActivity,serviceCollectionAdapter.getData().get(position).getGoods_id(),serviceCollectionAdapter.getData().get(position).getShop_id(),"");
                }
            });
    }

    @Override
    public void initInject() {
        DaggerMainActivityCompent.builder().applicationComponent(getApplicationComponent())

                .activityModule(getActivityModule()).build().inject(this);
    }

    @Override
    protected BasePresenter getPresenter() {
        return null;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void error(String msg) {

    }

    @Override
    public void error(int code, String msg) {

    }

    @Override
    public void getCollectGoodsSuccess(List<OrderType> allGood) {
        mStatusLayoutManager.showContent();
        serviceCollectionAdapter.setNewData(allGood);
        if (allGood.size() == 0) {
            serviceCollectionAdapter.setEmptyView(R.layout.layout_empty_address);
            ((TextView)serviceCollectionAdapter.getEmptyView().findViewById(R.id.tv_title)).setText("还没有相关收藏哦~");
        }
    }
}
